package com.szrt.java.day20170112.ch01;



import java.io.File;
import java.util.Arrays;

import org.junit.Test;

import com.szrt.java.utils.ScottFileUtil;

public class FileTest {
	
	
	@Test
	public void fiLeTest() throws Exception {
		
		//   2个斜杠   代表的是转义   /t table  /r/n 换行  // 反斜杠
		//   http://baike.baidu.com/link?url=Yw8nMVWhNPHmWjNYXWuGd-tXo7V7wSVCDAvFtKxmqECG21peqlpqVR5-f_JCr2QMLZ6XY_vXwSrgx4iRqtLWpK
		File file = new File("E://ac//cc.txt");
		File ccc = new File("E://ac//ccc.txt");
		File b = new File("E:/ac/bb");
		
		System.out.println(file.getName());
		
		System.out.println(file.isFile());
		
		System.out.println(b.isFile());
		System.out.println(b.isDirectory());
		
		System.out.println(file.length()); //utf-8   3
		System.out.println(ccc.length());  //gbk     2
		
		
		
		
	}
	
	
	@Test
	public void createFile() throws Exception {
		
		File file  = File.createTempFile("szrt10086", ".txt");
		
		System.out.println(file.getAbsolutePath());
		
		//创建1个文件
		File szrt = new File("F:/aa/bb/szrt2.txt");
		szrt.createNewFile();
		
		
		File ccc = new File("F:/aa/bb/ccc");
		boolean e = ccc.exists();
		
		System.out.println(e);
		
		ccc.mkdir();
		
	}
	
	
	@SuppressWarnings("unused")
	@Test
	public void testName() throws Exception {
		
		//成功创建1个文件有个前提：改文件所在的目录必须存在。
		File xxoo = new File("xxx/ooo/xxoo.txt");
		//xxoo.createNewFile();
		
		if(xxoo.isDirectory()){
			System.out.println("是文件夹...");
		}else{
			System.out.println("是文件...");
			
			File parent = xxoo.getParentFile();
			
			if(!parent.exists()){
				//如果这个目录不存才需要创建。如果已经存在就不需要创建。 建立好文件夹及子文件夹
				parent.mkdirs();
				
			}
			
			xxoo.createNewFile();
		}
		
		
		
		File szrt = new File("F:/aa/bb/szrt44.txt");
		//szrt.createNewFile();
	}
	
	
	@Test
	public void xxx() throws Exception {
		
		ScottFileUtil.createFile("src/com/szrt/java/day20170112/ch01/xxoo123.mp4");
		
	}
	
	@Test
	public void canWrite() throws Exception {
		
		File ccc = new File("F:/aa/bb/szrt.txt");
		System.out.println(ccc.canRead());
		System.out.println(ccc.canWrite());
		System.out.println(ccc.canExecute());
		
		
		File ddd = new File("F:/aa/bb/szrt2.txt");
		ddd.delete();
		
		File aa = new File("F:/aa");
		
		//没有递归
		String[] xx = aa.list();
		
		System.out.println(xx.length);
		
		System.out.println(Arrays.toString(xx));
		
		
		
		
	}

}
